package com.zjc.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zjc.common.R;
import com.zjc.pojo.Bulider;
import com.zjc.pojo.StuRoom;
import com.zjc.service.BuliderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 周佳成
 * @since 2023-09-17
 */
@RestController
@RequestMapping("/api/builder")
public class BuliderController {
	@Autowired
	BuliderService buliderService;
	@GetMapping("/find")
	public R<Page> GetBuilderPage(int pageNum, int pageSize){
		QueryWrapper<Bulider> wrapper = new QueryWrapper<>();
		Page<Bulider> page1 = new Page<>(pageNum,pageSize);
		buliderService.page(page1,wrapper);
		return R.success(page1);
	}
	@PutMapping("/update")
	public R<String> changeRoom(@RequestBody Bulider bulider){

		boolean rows=buliderService.updateById(bulider);
		if(rows){
			return R.success("修改成功");
		}
		else{
			return R.error("修改失败");
		}

	}
	@PostMapping("/add")
	public R<String> addRoom(@RequestBody Bulider bulider){
		Integer ldid = bulider.getLdId();
		LambdaQueryWrapper<Bulider> lambdaQueryWrapper = new LambdaQueryWrapper<>();
		lambdaQueryWrapper.eq(Bulider::getLdId,ldid);
		Bulider b = buliderService.getOne(lambdaQueryWrapper);
		if(b!=null){
			return R.error("楼栋号不能重复！！");
		}
		buliderService.save(bulider);
		return R.success("添加成功");
	}
}

